Vue.directive('enterNumber', {
    inserted: function (el) {
        el.addEventListener("keypress",function(e){
            e = e || window.event
            let charcode = typeof e.charCode === 'number' ? e.charCode : e.keyCode
            let re = /\d/
            if(!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey){
                if(e.preventDefault){
                    e.preventDefault()
                }else{
                    e.returnValue = false
                }
            }
        })
    }
})



function initVue(opts) {

    new Vue({
        el: '#app',
        data: function() {
            return {
                // topMenu: [[${topMenu}]],
                // bottomMenu: [[${bottomMenu}]],
                dataShow: true,
                currentPage: 1,
                pagesize: 10,
                pagesizeList: [5, 10, 20, 40, 60, 80],
                totalCount: 0,
                dataList: [],
                dialogVisible: false,
                dialogTitle: '新增',
                multipleSelection: [],
                genDestoryBtnShow: false,

                chkbox: [],

                prefix: opts.prefix,

                formData: opts.formData,

                formQuery: opts.formQuery,

                rules: opts.rules,

                fields: opts.fields,

                dialogDeployVisible: false,

                tableData3: []

            }
        },

        mounted() {
            this.handleUserList()
        },

        methods: {
            resetFormData() {opts.resetFormData(this)},
            resetQuery() {opts.resetQuery(this)},
            saveForm() {crud.saveForm(this)},
            deleteConfirm() {crud.deleteConfirm(this)},
            deployConfirm() {crud.deployConfirm(this)},
            handleUserList() {crud.handleUserList(this)},
            add() {crud.add(this)},
            update() {crud.update(this)},
            changeSelection(val) {this.multipleSelection = val},
            closeDialog() { crud.closeDialog(this)},
            rowClass () {return 'text-align: center;'},
            headClass() {return 'text-align: center;background:#eef1f6;'},
            queryBy() {crud.queryBy(this)},
            handleSizeChange(size) {crud.handleSizeChange(size, this)},
            handleCurrentChange(currentPage){crud.handleCurrentChange(currentPage, this)},
            copy() {crud.copy(this)},
            clear() {crud.clear(this)},
            goBack(){window.location.href='/'},
            hello(){console.log(this.chkbox)},
            genCode() {crud.genCode(this)},
            destroyCode() {crud.destroyCode(this)},
            openUrl() {crud.openUrl(this)},
            copyCmd() {crud.copyCmd(this)},
            checkPoint() {crud.checkPoint(this)},


        }

    })

}